//
//  STMOrderModifyViewController.m
//  StoreManagement
//
//  Created by centling on 16/6/6.
//  Copyright © 2016年 alfred. All rights reserved.
//

#import "STMOrderModifyViewController.h"

@interface STMOrderModifyViewController ()
@property (weak, nonatomic) IBOutlet UITextField *sumPriceTf;
@property (weak, nonatomic) IBOutlet UITextField *freightTF;
@property (weak, nonatomic) IBOutlet UIButton *doneButton;
@property (weak, nonatomic) IBOutlet UIButton *cancelButton;

@end

@implementation STMOrderModifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.orderIdLabel.text = self.modifyOrderId;
    [self.doneButton addTarget:self action:@selector(doneButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.cancelButton addTarget:self action:@selector(cancelButtonClick) forControlEvents:UIControlEventTouchUpInside];
}


- (void)doneButtonClick {
    if ([self.sumPriceTf.text isEqualToString:@""] || [self.freightTF.text isEqualToString:@""]) {
        [GlobalUtil HUDShowMessage:@"信息输入不完整" addedToView:self.view];
        return;
    }
    NSInteger orderAmount = [self.sumPriceTf.text integerValue] + [self.freightTF.text integerValue];
    [STMNetworkAPI modifyOrderWithKey:[UserDefaultHandler getUserDetaultString:kUserKey]
                          orderAmount:[NSString stringWithFormat:@"%ld", (long)orderAmount]
                          goodsAmount:self.sumPriceTf.text
                          shippingFee:self.freightTF.text
                              orderId:self.orderIdLabel.text
                              success:^(STMLoginModel *result) {
                                  if ([result.code isEqualToString:@"200"]) {
                                      [[NSNotificationCenter defaultCenter] postNotificationName:nOrderPageRefresh object:nil];
                                      UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
                                      [nav popViewControllerAnimated:YES];
                                  } else if ([result.code isEqualToString:@"401"]) {
                                      [GlobalUtil presentLoginVC];
                                  } else {
                                      [GlobalUtil HUDShowMessage:result.message addedToView:self.view];
                                  }
                              }
                              failure:^(NSError *err) {
                                  [GlobalUtil HUDShowMessage:@"请检查网络连接" addedToView:self.view];
                              }];
}


- (void)cancelButtonClick {
    UINavigationController *nav = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    [nav popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
